<?php
/**
 * 检查敏感词函数( 包括高低2类敏感词 )
 * @param string $content
 * @return boolean 没有敏感词返回true,否则返回false
 */
function oa_checkSensitiveWord( $content ) {
	return true;
}

/**
 * Escapes text to make it safe to use with Javascript
 *
 * It is usable as, e.g.:
 *  echo '<script>aiert(\'begin'.escape_js_quotes($mid_part).'end\');</script>';
 * OR
 *  echo '<tag onclick="aiert(\'begin'.escape_js_quotes($mid_part).'end\');">';
 * Notice that this function happily works in both cases; i.e. you don't need:
 *  echo '<tag onclick="aiert(\'begin'.txt2html_old(escape_js_quotes($mid_part)).'end\');">';
 * That would also work but is not necessary.
 *
 * @param  string $str    The data to escape
 * @param  bool   $quotes should wrap in quotes (isn't this kind of silly?)
 * @return string         Escaped data
 */
function escape_js_quotes($str, $quotes=false) {
    if ($str === null) {
        return;
    }
    $str = strtr($str, array('\\'=>'\\\\', "\n"=>'\\n', "\r"=>'\\r', '"'=>'\\x22', '\''=>'\\\'', '<'=>'\\x3c', '>'=>'\\x3e', '&'=>'\\x26'));
    return $quotes ? '"'. $str . '"' : $str;
}

if (! function_exists('str_startwith')) {
    function str_startwith($haystack, $needle)
    {
        return strpos($haystack, $needle) === 0;       
    }
}

/*!
 * 截取utf-8编码的中文字符，$length是半角字符的个数
 * 如果超过给定的$length,将加入一个省略号
 */
function utf_substr ($string, $length) {
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $info);  
    for($i=0; $i<count($info[0]); $i++) {
        $wordscut .= $info[0][$i];
        $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
        if ($j > $length - 3) {
           return $wordscut."…";
        }
    }
    return join('', $info[0]);
} 
